package framework.utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

import framework.exceptions.ExceptionHandler;
import play.db.DB;

public class DBUtil {

private final static  Logger logger = LogUtil.getInstance(DBUtil.class);
    
    /**
     * 获取应用的JDBC连接
     * @return
     */
    public static Connection  getConnection(){
        return DB.getConnection();
    }
    
    
    public static ResultSet query(String sql){
        Connection conn = getConnection();
        Statement stmt;
        ResultSet rs=null;
        try {
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
        } catch (SQLException e) {
            ExceptionHandler.throwRuntimeException(e, "数据字典加载内存数据连接异常");
            logger.error("数据字典加载内存数据连接异常");
        }finally{
            try {
                if(conn!=null){
                    conn.close();
                    conn =null;
                }
            } catch (SQLException e) {
                logger.error("数据库连接关闭异常");
            }
        }
        return rs;
    }
}
